package com.qianfeng.wuyang.himalaya.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianfeng.wuyang.himalaya.R;
import com.qianfeng.wuyang.himalaya.activity.MyApplication;
import com.qianfeng.wuyang.himalaya.adapter.clsssifyadapter.Adapter_classify;
import com.qianfeng.wuyang.himalaya.bean.classifybean.Entity_Classify;
import com.qianfeng.wuyang.himalaya.bean.classifybean.Entity_classifyTop;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
//
public class ClassifyFragment extends Fragment implements Callback<Entity_classifyTop> {
    private List<Entity_Classify> list_data;

    private Adapter_classify adapter;
    private RecyclerView recyclerView;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        list_data = new ArrayList<>();
        return inflater.inflate(R.layout.fragment_classify, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        MyApplication application = (MyApplication) getActivity().getApplication();
        application.getService().getClassifyList("and-a1", "android", 13, 2).enqueue(this);

        recyclerView= (RecyclerView) view.findViewById(R.id.classify_recyclerView);
        adapter=new Adapter_classify(list_data,getContext());
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onResponse(Call<Entity_classifyTop> call, Response<Entity_classifyTop> response) {
            list_data.addAll(response.body().getList());
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onFailure(Call<Entity_classifyTop> call, Throwable t) {

    }
}
